import * as ENUM from "./enum";
type enumType = {
  [key: string]: any;
};
type eTypea = {
  value?: string | number;
  label?: string;
};
/**
 * 字典数据
 * @returns
 */
export const useEnum = (name: string = "") => {
  const DICT: enumType = ENUM;
  /**
   * 获取指定key的对象
   */
  const useEnumItem = (value: string | number, key: string = "") => {
    const EnumList = getEnumList(key);
    if (!EnumList || (EnumList && !EnumList.length)) {
      return null;
    }
    // 过滤
    const filterItem = EnumList.filter((e: eTypea) => e.value === value);
    if (!filterItem.length) {
      return null;
    }
    return filterItem[0];
  };
  /**
   * @returns 获取列表
   */
  const getEnumList = (key: string = "") => DICT?.[key] || DICT[name];

  return {
    getEnumList,
    useEnumItem,
  };
};
